package com.atguigu.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ Author:任留辉
 * @ Description:
 * @ Date:Created in 10:07 2021/3/17 0017
 */
public class GetCookieServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //获取cookie
            Cookie[] cookies = request.getCookies();
            if(cookies != null){
           for (Cookie cookie : cookies) {
              /* if(cookie.getName().equals("username")){
                   cookie.setValue("web");
               }*/
               System.out.println(cookie.getName()+"=="+cookie.getValue());
           }
       }
    }
}
